var a = getApp();

Page({
    data: {
        firstCategory: [],
        secondCategory: [],
        first_id: -1,
        second_id: -1,
        list: [],
        page: 1
    },
    onLoad: function(a) {
        this.getFirstCategory();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var a = this.data.page + 1;
            this.setData({
                page: a
            }), this.getMoreData();
        }
    },
    onShareAppMessage: function() {},
    getFirstCategory: function() {
        var t = this, e = a.getNetAddresss("plugin.case-library.api.case.get-all-category");
        a._postNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                console.log(e), 1 == e.result ? (t.setData({
                    firstCategory: e.data.firstCategory
                }), e.data.firstCategory.length >= 1 && t.changeFirstCategory("", t.data.firstCategory[0].id)) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a), wx.hideLoading({
                    success: function(a) {}
                });
            }
        });
    },
    changeFirstCategory: function(t, e) {
        var s = this;
        if (e && this.setData({
            first_id: e
        }), t) {
            console.log(t);
            var o = t.currentTarget.dataset.id;
            this.setData({
                first_id: o
            });
        }
        var i = a.getNetAddresss("plugin.case-library.api.mobile.home.cut-first-category");
        a._postNetWork({
            url: i,
            data: {
                pid: s.data.first_id
            },
            success: function(a) {
                var t = a.data;
                console.log(t), 1 == t.result ? s.setData({
                    secondCategory: t.data.secondCategory,
                    list: t.data.case.data,
                    current_page: t.data.case.current_page,
                    last_page: t.data.case.last_page,
                    second_id: -1
                }) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a), wx.hideLoading({
                    success: function(a) {}
                });
            }
        });
    },
    changeSecondCategory: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.id, s = this, o = a.getNetAddresss("plugin.case-library.api.mobile.home.cut-second-category");
        a._postNetWork({
            url: o,
            data: {
                cid: e
            },
            success: function(a) {
                var t = a.data;
                console.log(t), 1 == t.result ? s.setData({
                    list: t.data.case.data,
                    current_page: t.data.case.current_page,
                    last_page: t.data.case.last_page
                }) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a), wx.hideLoading({
                    success: function(a) {}
                });
            }
        });
    },
    getMoreData: function() {
        var t, e = this, s = [];
        -1 == this.data.second_id ? (t = a.getNetAddresss("plugin.case-library.api.mobile.home.cut-first-category"), 
        s = {
            pid: e.data.first_id,
            page: e.data.page
        }) : (t = a.getNetAddresss("plugin.case-library.api.mobile.home.cut-second-category"), 
        s = {
            cid: e.data.second_id,
            page: e.data.page
        }), a._postNetWork({
            url: t,
            data: s,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    var s = t.data.case.data;
                    e.setData({
                        list: e.data.list.concat(s),
                        current_page: t.data.case.current_page,
                        last_page: t.data.case.last_page
                    });
                } else wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a), wx.hideLoading({
                    success: function(a) {}
                });
            }
        });
    }
});